package dapps.web.monitor;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.security.springsecurity.SpringSecurityUtils;

import com.opensymphony.xwork2.ActionSupport;

import dapps.entity.monitor.Fieldvalue;
import dapps.entity.user.District;
import dapps.service.monitor.MonitorManager;
import dapps.service.user.UserManager;

@SuppressWarnings("serial")
public class ProblemAction extends ActionSupport {

	@Autowired
	private MonitorManager mManager;
	@Autowired
	private UserManager uManager;
	// private HttpServletRequest request = Struts2Utils.getRequest();

	private List<Fieldvalue> splist;
	private String reportDate;
	private String field;
	private Long districtid;
	private List<District> districtlist;

	@Override
	public String execute() throws Exception {
		int i=0;
		if(SpringSecurityUtils.getAuthority("A_ALL_DISTRICT")){
			districtlist = uManager.getDistrictlist(null,null, null);
			i=1;
		}
		//未选 或 未跨区授权
		if(districtid==null||i==0) {
			Long udistrictid = SpringSecurityUtils.getCurrentUser().getDistrict().getId();
			if(udistrictid!=null&&udistrictid>0L){
				districtid = udistrictid;
			}else{
				districtid=null;
			}
		}
		if(districtid!=null&&StringUtils.isNotBlank(field)&&StringUtils.isNotBlank(reportDate))
		splist = mManager.getProblem(reportDate, field, districtid);
		return SUCCESS;
	}

	public List<Fieldvalue> getSplist() {
		return splist;
	}

	public void setSplist(List<Fieldvalue> splist) {
		this.splist = splist;
	}

	public String getField() {
		return field;
	}

	public void setField(String field) {
		this.field = field;
	}


	public String getReportDate() {
		return reportDate;
	}

	public void setReportDate(String reportDate) {
		this.reportDate = reportDate;
	}



	public Long getDistrictid() {
		return districtid;
	}

	public void setDistrictid(Long districtid) {
		this.districtid = districtid;
	}

	public List<District> getDistrictlist() {
		return districtlist;
	}

}
